#include "log_level.h"

#include <array>
#include <cstring>

namespace Base {
namespace SystemLog {
const char* LogLevelToString(LogLevel level) {
    static const std::array<const char*, LOG_LEVEL_COUNT> levelStrings = {
        "TRACE", "DEBUG", "INFO ", "WARN ", "ERROR", "FATAL"
    };

    if (level < LOG_LEVEL_TRACE || level >= LOG_LEVEL_COUNT) {
        return "UNKNOWN";
    }
    return levelStrings[level];
}

LogLevel StringToLogLevel(const char* str) {
    if (str == nullptr) {
        return LOG_LEVEL_INFO;
    }

    if (std::strcmp(str, "TRACE") == 0) {
        return LOG_LEVEL_TRACE;
    }
    if (std::strcmp(str, "DEBUG") == 0) {
        return LOG_LEVEL_DEBUG;
    }
    if (std::strcmp(str, "INFO") == 0) {
        return LOG_LEVEL_INFO;
    }
    if (std::strcmp(str, "WARN") == 0) {
        return LOG_LEVEL_WARN;
    }
    if (std::strcmp(str, "ERROR") == 0) {
        return LOG_LEVEL_ERROR;
    }
    if (std::strcmp(str, "FATAL") == 0) {
        return LOG_LEVEL_FATAL;
    }

    return LOG_LEVEL_INFO; // 默认级别
}
} // namespace SystemLog
} // namespace Base